package com.itstyle.seckill.topic.diruptor;

import com.itstyle.seckill.queue.disruptor.SeckillEvent;
import com.lmax.disruptor.EventTranslatorVararg;
import com.lmax.disruptor.RingBuffer;

/**
 * @Auther: liuwenxiang
 * @Date: 2020/4/3 15:53
 * @Description:
 * 生产者
 */
public class LongEventProducer {



    private final static EventTranslatorVararg<LongEvent> trans = new EventTranslatorVararg<LongEvent>(){

        @Override
        public void translateTo(LongEvent longEvent, long l, Object... objects) {
            longEvent.setUserId((Integer) objects[0]);
            longEvent.setLog((String) objects[1]);
        }
    };



    private final  RingBuffer<LongEvent> ringBuffer;

    public LongEventProducer(RingBuffer<LongEvent> ringBuffer){
        this.ringBuffer=ringBuffer;
    }



    public void publish(int userId,String log){
        //发布事件
        ringBuffer.publishEvent(trans,userId,log);
    }
}
